﻿using Microsoft.Office.Interop.Excel;

namespace HmLab.Func2;

internal class LbFillYearResult {

  /// <summary>
  /// FillResult(string
  /// <see cref="Haimen.Func2.YearResultMaker"/>
  /// <see cref="Program.Main"/>
  /// </summary>
  public void Run() {
    System.Console.WriteLine("LbFillYearResultLbFillYearResult");

    string fromPath = @"D:\work\personal\nina\2023haimen2\workshop_cslab\输Q出f2\月合并报表.xlsx";
    string month = "1月";
    string resultPath = @"D:\work\personal\nina\2023haimen2\workshop_cslab\输Q出f2\年汇总表.xlsx";

    Application excelApp = new() {
      Visible = true,
      //ScreenUpdating = false,
    };

    Workbooks books = excelApp.Workbooks;
    Workbook toBook = books.Open(resultPath);

    excelApp.DisplayAlerts = false;
    BookFrom[] copyArg = MakeCopyArg(fromPath, month);
    _interopCopier.Copy(toBook, copyArg);

    excelApp.ScreenUpdating = true;
  }

  BookFrom[] MakeCopyArg(string fromPath, string month) {
    CellCopy cellArg = new(FromRange: "A1:", ToCell: "A1");
    SheetTo sheetTo = new(month, From: [new("汇总表", [cellArg])]);
    BookFrom bookFrom = new(fromPath, [sheetTo]);
    return [bookFrom];
  }

  readonly LbExcelCopyRange.Copier _interopCopier = new(new());
}
